package com.boatAnchorAssistant.service.controller.web;

import com.boatAnchorAssistant.pojo.param.alarmCause.*;
import com.boatAnchorAssistant.pojo.vo.alarmCause.*;
import com.boatAnchorAssistant.service.service.in.*;
import nirvana.core.domains.vo.PageResult;
import nirvana.core.domains.vo.ApiResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

import java.util.List;

/**
 * web/报警原因
 * 【描 述】：
 * 【环 境】：J2SE
 * 【详 细】：
 */
@RestController
@RequestMapping("/alarmCause/web")
public class AlarmCauseWebController {

    private final AlarmCauseService service;

    public AlarmCauseWebController(AlarmCauseService service) {
        this.service = service;
    }


    /**
     * 创建报警原因
     *
     * @param param
     * @return
     */
    @PostMapping("/createAlarmCause")
    public ApiResult createAlarmCause(@RequestBody @Valid CreateAlarmCauseParam param) {
        service.createAlarmCause(param);
        return ApiResult.ok();
    }


    /**
     * 修改报警原因
     *
     * @param param
     */
    @PutMapping("/editAlarmCause")
    public ApiResult editAlarmCause(@RequestBody @Valid EditAlarmCauseParam param) {
        service.editAlarmCause(param);
        return ApiResult.ok();
    }

    /**
     * 移除报警原因
     *
     * @param id
     */
    @DeleteMapping("/removeAlarmCause")
    public ApiResult removeAlarmCause(@RequestParam("id") Long id) {
        service.removeAlarmCause(id);
        return ApiResult.ok();
    }

    /**
     * 启动/禁用报警原因
     *
     * @param id
     */
    @GetMapping("/enabledAlarmCause")
    public ApiResult enabledAlarmCause(@RequestParam("id") Long id) {
        service.enabledAlarmCause(id);
        return ApiResult.ok();
    }

    /**
     * 获取报警原因详情
     *
     * @param id
     * @return
     */
    @GetMapping("/getAlarmCause")
    public ApiResult<GetAlarmCauseVo> getAlarmCause(@RequestParam("id") Long id) {
        GetAlarmCauseVo vo = service.getAlarmCause(id);
        return ApiResult.ok(vo);
    }

    /**
     * 获取报警原因列表
     *
     * @param param
     * @return
     */
    @PostMapping("/getAlarmCauseList")
    public ApiResult<PageResult<GetAlarmCauseListVo>> getAlarmCauseList(@RequestBody GetAlarmCauseListParam param) {
        PageResult<GetAlarmCauseListVo> result = service.getAlarmCauseList(param);
        return ApiResult.ok(result);
    }


    /**
     * 获取报警原因下拉列表
     *
     * @return
     */
    @PostMapping("/getAlarmCauseDownList")
    public ApiResult<List<GetAlarmCauseDownListVo>> getAlarmCauseDownList(@RequestBody(required = false) @Valid GetAlarmCauseDownListParam param) {
        List<GetAlarmCauseDownListVo> list = service.getAlarmCauseDownList(param);
        return ApiResult.ok(list);
    }


}

